package com.hongkuncheng.cms.controller.interfaces;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Controller;
import com.hongkuncheng.cms.controller.BaseController;
import com.hongkuncheng.cms.helper.HttpHelper;
import com.hongkuncheng.cms.helper.WeiboHelper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 微博接口
 *
 * @author 洪坤成
 */
@Controller
@Transactional
@RequestMapping("interfaces/weibo")
@ResponseBody
public class InweiboController extends BaseController {

    // 微博回传
    @RequestMapping("callback")
    public void callback() throws Exception {
        String code = request.getParameter("code");
        if (code != null) {
            String token = WeiboHelper.getAccessToken(HttpHelper.getHost(request), code);
            if (token != null) {
                request.getSession().setAttribute("weiboAccessToken", token);
                response.sendRedirect("/admin/weibo/sync");
            }
        } else {
            print("your code is empty!");
        }
    }

}
